Skip to content

Conversation

@agusmdev
Copy link
Owner

Summary

This PR adds a new --history mode to CCV that allows you to read past Claude Code sessions from ~/.claude/projects/ and display them as formatted conversation transcripts.

Features

New CLI Flags

Flag Description
--history <path> Read sessions from a JSONL file or directory
--since <date> Filter sessions modified since date (YYYY-MM-DD)
--last <n> Show only the last N sessions
--project <name> Find project by name in ~/.claude/projects/

Output Format

Session: 2025-01-20 14:32:05 - 15:17:42 (45 min)
Project: /Users/me/myproject

---

[14:32:05]
User: Fix the authentication bug in login.go

[14:32:12]
Assistant: I will analyze the authentication code and fix the bug.

The issue was in the JWT validation logic...

Tools: Read(3), Edit(1)
Tokens: 1,234 in / 567 out

---

Total: 12,500 in / 3,200 out

Usage Examples

# View all sessions for a project directory
ccv --history ~/.claude/projects/-Users-me-myproject/

# View a specific session file
ccv --history path/to/session.jsonl

# Find project by name (searches ~/.claude/projects/)
ccv --history --project myproject

# Show only the last 3 sessions
ccv --history --last 3 --project myproject

# Show sessions modified since a date
ccv --history --since 2025-01-20 --project myproject

# Combine filters
ccv --history --since 2025-01-20 --last 5 --project myproject

Implementation Details

New Files

  • history.go (410 lines): Contains HistoryReader for parsing JSONL session files and formatting output
    • Parses sessions-index.json for session metadata
    • Falls back to listing .jsonl files if index is missing
    • Groups messages into conversation turns
    • Skips tool_result messages (they are internal responses)
    • Excludes thinking blocks from output
    • Accumulates tool counts and token usage per turn

Modified Files

  • main.go: Added flag parsing for --history, --since, --last, --project
  • types.go: Added SessionIndex and SessionIndexEntry structs

Key Design Decisions

  1. Streaming-friendly: Processes JSONL line-by-line without loading entire file into memory
  2. Graceful degradation: Falls back to listing files if sessions-index.json is missing
  3. Tool result filtering: Skips internal tool_result messages (not user prompts)
  4. Thinking block exclusion: Only shows assistant text, not internal reasoning
  5. Flexible date parsing: Supports multiple date formats for --since

Test Plan

  • Build: make build succeeds
  • Test with real session directory: ccv --history ~/.claude/projects/-Users-me-project/
  • Test with direct session file: ccv --history path/to/session.jsonl
  • Test --project flag: ccv --history --project myproject
  • Test --last filter: ccv --history --last 3 --project myproject
  • Test --since filter: ccv --history --since 2025-01-20 --project myproject
  • Verify output shows correct timestamps, user prompts, assistant text, tool counts, and tokens

🤖 Generated with Claude Code

Claude Agent and others added 2 commits January 21, 2026 21:47
Add ability to read and display past Claude Code sessions from
~/.claude/projects/ as formatted conversation transcripts.

New features:
- --history <path>: Read sessions from file or directory
- --since <date>: Filter sessions by modification date
- --last <n>: Show only the last N sessions
- --project <name>: Find project by name in ~/.claude/projects/

Output format shows:
- Session time range and duration
- Project path
- Each conversation turn with timestamp
- User prompts and assistant responses (no thinking blocks)
- Tool usage summary per turn (e.g., "Read(3), Edit(1)")
- Token counts per turn and session totals

New files:
- history.go: HistoryReader, JSONL parsing, conversation turn building

Modified files:
- main.go: Flag parsing for history mode options
- types.go: SessionIndex and SessionIndexEntry structs

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants